#include "StdAfx.h"
#include "UILabel.h"

/////////////////////////////////////////////////////////////////////////////////////

CLabelPanelUI::CLabelPanelUI() : m_uTextStyle(DT_VCENTER) {
}

LPCTSTR CLabelPanelUI::GetClass() const {
    return _T("LabelPanelUI");
}

void CLabelPanelUI::SetText(LPCTSTR pstrText) {
    CControlUI::SetText(pstrText);
}

void CLabelPanelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) {
	if (_tcscmp(pstrName, _T("align")) == 0) {
		if (_tcsstr(pstrValue, _T("center")) != NULL) m_uTextStyle |= DT_CENTER;
		if (_tcsstr(pstrValue, _T("right")) != NULL) m_uTextStyle |= DT_RIGHT;
	}
	else {
		CControlUI::SetAttribute(pstrName, pstrValue);
	}
}

void CLabelPanelUI::DoPaint(HDC hDC, const RECT& rcPaint) {
    RECT rcText = m_rcItem;
	CBlueRenderEngineUI::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, UICOLOR_EDIT_TEXT_NORMAL, UICOLOR__INVALID, DT_SINGLELINE | m_uTextStyle);
}

/////////////////////////////////////////////////////////////////////////////////////

CTextPanelUI::CTextPanelUI() : m_uButtonState(0), m_TextColor(UICOLOR_EDIT_TEXT_NORMAL), m_BackColor(UICOLOR_STANDARD_RED) {
	m_uTextStyle = DT_WORDBREAK;
}

LPCTSTR CTextPanelUI::GetClass() const {
	return _T("TextPanelUI");
}

bool CTextPanelUI::Activate() {
	if (!CLabelPanelUI::Activate()) return false;
	return true;
}

void CTextPanelUI::SetTextColor(UITYPE_COLOR TextColor) {
	m_TextColor = TextColor;
	Invalidate();
}

void CTextPanelUI::SetBkColor(UITYPE_COLOR BackColor) {
	m_BackColor = BackColor;
	Invalidate();
}

void CTextPanelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) {
	if (_tcscmp(pstrName, _T("textColor")) == 0) SetTextColor((UITYPE_COLOR)_ttoi(pstrValue));
	else if (_tcscmp(pstrName, _T("backColor")) == 0) SetBkColor((UITYPE_COLOR)_ttoi(pstrValue));
	else CLabelPanelUI::SetAttribute(pstrName, pstrValue);
}

void CTextPanelUI::DoPaint(HDC hDC, const RECT& rcPaint) {
	RECT rcText = m_rcItem;
	CBlueRenderEngineUI::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, m_TextColor, m_BackColor, m_uTextStyle);
}